package com.wolves.career.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wolves.career.entity.RealTimeForumTopic;
import com.wolves.career.mapper.RealTimeForumTopicMapper;
import com.wolves.career.service.RealTimeForumTopicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import javax.management.Query;
import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-27
 */
@Service
public class RealTimeForumTopicServiceImpl extends ServiceImpl<RealTimeForumTopicMapper, RealTimeForumTopic> implements RealTimeForumTopicService {


    @Override
    public QueryWrapper<RealTimeForumTopic> getTopicQueryWrapper(RealTimeForumTopic topic) {
        QueryWrapper<RealTimeForumTopic> queryWrapper = new QueryWrapper<>();
        Integer topicId = topic.getTopicId();
        String content = topic.getContent();
        Integer isPass = topic.getIsPass();
        Integer thumbsUp = topic.getThumbsUp();
        String title = topic.getTitle();
        Date releaseTime = topic.getReleaseTime();
        Integer rate = topic.getRate();
        Integer visitTheNumber = topic.getVisitTheNumber();
        Integer userId = topic.getUserId();
        Date updateTime = topic.getUpdateTime();
        if (!StringUtils.isEmpty(topicId)) {
            queryWrapper.eq("topic_id", topicId);
        }
        if (!StringUtils.isEmpty(content)) {
            //模糊查询文章内容
            queryWrapper.like("content", content);
        }
        if (!StringUtils.isEmpty(isPass)) {
            queryWrapper.eq("is_pass", isPass);
        }
        if (!StringUtils.isEmpty(thumbsUp)) {
            //获取点赞数在此之上的
            queryWrapper.gt("thumbs_up", thumbsUp);
        }
        if (!StringUtils.isEmpty(title)) {
            queryWrapper.like("title", title);
        }
        if (!StringUtils.isEmpty(releaseTime)) {
            //在此时间之后发布的文章
            queryWrapper.gt("release_time", releaseTime);
        }
        if (!StringUtils.isEmpty(rate)) {
            //获取评级更高的
            queryWrapper.gt("rate", rate);
        }
        if (!StringUtils.isEmpty(visitTheNumber)) {
            //获取浏览量更高的
            queryWrapper.gt("Visit_the_number", visitTheNumber);
        }
        if (!StringUtils.isEmpty(userId)) {
            queryWrapper.eq("user_id", userId);
        }
        if (!StringUtils.isEmpty(updateTime)) {
            //获取更新时间在此之后的
            queryWrapper.lt("update_time", updateTime);
        }
        return queryWrapper;
    }
}
